//
//  AppDelegate.m
//  QingDaoCommunity
//
//  Created by 李学林 on 15/11/21.
//  Copyright © 2015年 teteTechnology. All rights reserved.
//

#import "AppDelegate.h"

#import "LFTabBarController.h"

/**
 *  这里是控制器
 *
 */
#import "LFHomeViewController.h"
#import "LFToolsViewController.h"
#import "LFHotsViewController.h"
#import "LFCircleViewController.h"
#import "LFOnliveViewController.h"
#import "LFShakeViewController.h"
#import "LFUSViewController.h"
#import "LFXMLLViewController.h"
#import "LFGuideViewController.h"
#import "UMSocial.h"

//#import "UMSocialSinaSSOHandler.h"这是原生
#import "UMSocialSinaHandler.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    [UMSocialData setAppKey:@"5656f9e867e58e5f4e0008fd"];
    
    
    [UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    [self enterMain];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterMain) name:kNoticeficationGuide object:nil];

    [self.window makeKeyAndVisible];

    // 第一次进入的时候记录 进入guide
    BOOL flag = [[NSUserDefaults standardUserDefaults] boolForKey:kGuideLaunch];
    
    if (flag) {
        //进入到主视图
        [self enterMain];
    }else{
        LFGuideViewController *guide = [[LFGuideViewController alloc]init];
        
        self.window.rootViewController = guide;
        
    }
    
    return YES;
}

- (void)enterMain{

    UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    
    //用于存储tabbar的子控制器
    NSMutableArray *tabArray = [NSMutableArray array];
    
    NSArray *array = @[@"LFHomeViewController",@"LFHotsViewController",@"LFCircleViewController",@"LFToolsViewController",@"LFShakeViewController",@"LFXMLLViewController",@"LFOnliveViewController",@"LFUSViewController"];
    
    for (NSString *clsStr in array) {
        
        UIViewController *vc = [main instantiateViewControllerWithIdentifier:clsStr];
        
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        
        
        [tabArray addObject:nav];
    }
    
    
    
    self.tab = [[LFTabBarController alloc]init];
    
    self.tab.viewControllers = tabArray;
    
    self.window.rootViewController = self.tab;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)dealloc{

    [[NSNotificationCenter defaultCenter]removeObserver:self]; 

}


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;
}

@end
